#!/bin/bash
# Author : Syuan-Rong Chen
# E-mail : calvin.atx@gmail.com
# Blog：   http://calvinit.blogspot.com
# Date : 20100811
#
# <description>
# Copyright (C) <year>  <name> <email>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .
#
druser=$HOME/calvin/bhuser/user.txt

#判斷user.txt中的使用者是否已建立
uc1=$(tail -1 $druser |cut -d: -f1)
uc2=$(cat /etc/passwd | grep /home/$uc1)

if [ $? == "0" ]; then 
	echo -ne "使用者已存在，無法建立...(請按任何鍵)"
	read
	. /usr/cbin/d-bhuser/main.sh 
fi

s=$(cat $druser)

for us in $s
do
	u1=${us%%:*}
	u2=${us##*:}
	echo $u1已建立

	useradd  -m  -s /bin/bash $u1
	echo "$u1:$u2" | chpasswd
done
